package com.dzl.movie;

import com.alibaba.fastjson.JSONObject;
import com.dzl.base.controller.BaseController;
import com.dzl.moive.pojo.WelfareMovieInfo;
import com.dzl.moive.pojo.dto.WelfareMoviePremiumPriceDto;
import com.dzl.moive.pojo.query.WelfareMovieInfoManageQuery;
import com.dzl.moive.service.WelfareMovieInfoService;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import com.dzl.util.PageUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 电影基础信息(welfare_movie_info)表控制层
 * @author ChenLong
 * @date 2021-11-02 16:04:29
 */
@RestController
@RequestMapping("/welfareMovieInfo")
public class WelfareMovieInfoController extends BaseController {

    @Autowired
    private WelfareMovieInfoService service;

    /**
     * 获取热映电影或待映电影
     * @param query 影片查询实体
     * @author ChenLong
     * @date 2021-11-02 16:12:50
     **/
    @GetMapping(value = "getMovieInfoManageList")
    public PageUtils<WelfareMovieInfo> getMovieInfoManageList(WelfareMovieInfoManageQuery query) {
        PageInfo<WelfareMovieInfo> pageInfo = service.getMovieInfoManageListPage(query);
        return new PageUtils<>(pageInfo);
    }

    /**
     * 修改溢价
     * @param welfareMoviePremiumPriceDto 影片溢价信息
     * @author ChenLong
     * @date 2021-11-02 16:12:50
     **/
    @PostMapping(value = "updateMoviePremiumPrice")
    public JsonResult<Integer> updateMoviePremiumPrice(@RequestBody WelfareMoviePremiumPriceDto welfareMoviePremiumPriceDto) {
        if (EmptyUtils.isEmpty(welfareMoviePremiumPriceDto.getIds())){
            return JsonResult.paramErrWithMsg("请选择影片");
        }
        if (welfareMoviePremiumPriceDto.getPremiumPrice() == null){
            return JsonResult.paramErrWithMsg("请输入溢价");
        }
        return JsonResult.success(service.updateMoviePremiumPrice(welfareMoviePremiumPriceDto));
    }

    /**
     * 修改全部溢价
     * @param
     * @author ChenLong
     * @date 2021-11-02 16:12:50
     **/
    @PostMapping(value = "updateAllMoviePremiumPrice")
    public JsonResult<Integer> updateAllMoviePremiumPrice(@RequestBody JSONObject jsonObject) {
        BigDecimal premiumPrice = jsonObject.getBigDecimal("premiumPrice");
        if (EmptyUtils.isEmpty(premiumPrice)){
            return JsonResult.paramErrWithMsg("溢价为空");
        }
        return JsonResult.success(service.updateAllMoviePremiumPrice(premiumPrice));

    }
}
